var t = function() {};

function r(t) {
    for (var r = 1; t(r) > 0; ) r += 1;
    for (;t(r) < 0; ) r -= .01;
    return r + .01;
}

function o(t, r, o) {
    for (var e = 0, n = 0, a = 0; a < t.length; a++) e += t[a] / Math.pow(1 + o, r[a]);
    for (a = 0; a < t.length; a++) n += -t[a] * r[a] * Math.pow(1 + o, -1 - r[a]);
    return e / n;
}

t.prototype.PV = function(t, r, o) {
    o = void 0 !== o ? o : 1;
    var e;
    t /= 100;
    return e = r / Math.pow(1 + t, o), Math.round(100 * e) / 100;
}, t.prototype.FV = function(t, r, o) {
    var e;
    t /= 100;
    return e = r * Math.pow(1 + t, o), Math.round(100 * e) / 100;
}, t.prototype.NPV = function(t) {
    t /= 100;
    for (var r = arguments[1], o = 2; o < arguments.length; o++) r += arguments[o] / Math.pow(1 + t, o - 1);
    return Math.round(100 * r) / 100;
}, t.prototype.IRR = function(t) {
    var o, e, n = arguments, a = 1;
    if (Array.prototype.slice.call(n).forEach(function(t) {
        t > 0 && (o = !0), t < 0 && (e = !0);
    }), !o || !e) throw new Error("IRR requires at least one positive value and one negative value");
    function u(t) {
        if (++a > 1e5) throw new Error("IRR can't find a result");
        for (var r = 1 + t / 100, o = n[0], e = 1; e < n.length; e++) o += n[e] / Math.pow(r, e);
        return o;
    }
    return Math.round(100 * r(u)) / 100;
}, t.prototype.IRR2 = function(t, r) {
    r = r || 0;
    for (var o = function(t, r, o) {
        for (var e = o + 1, n = t[0], a = 1; a < t.length; a++) n += t[a] / Math.pow(e, (r[a] - r[0]) / 365);
        return n;
    }, e = function(t, r, o) {
        for (var e = o + 1, n = 0, a = 1; a < t.length; a++) {
            var u = (r[a] - r[0]) / 365;
            n -= u * t[a] / Math.pow(e, u + 1);
        }
        return n;
    }, n = [], a = !1, u = !1, i = 0; i < t.length; i++) n[i] = 0 === i ? 0 : n[i - 1] + 365, 
    t[i] > 0 && (a = !0), t[i] < 0 && (u = !0);
    if (!a || !u) throw new Error("IRR requires at least one positive value and one negative value");
    var p, h, f, v = r = void 0 === r ? .1 : r, c = !0;
    do {
        p = v - (f = o(t, n, v)) / e(t, n, v), h = Math.abs(p - v), v = p, c = h > 1e-10 && Math.abs(f) > 1e-10;
    } while (c);
    return (100 * v).toFixed(2);
}, t.prototype.PP = function(t, r) {
    if (0 === t) return Math.abs(arguments[1]) / arguments[2];
    for (var o = arguments[1], e = 1, n = 2; n < arguments.length; n++) {
        if ((o += arguments[n]) > 0) return (e += (o - arguments[n]) / arguments[n]).toFixed(2);
        e++;
    }
}, t.prototype.ROI = function(t, r) {
    var o = (r - Math.abs(t)) / Math.abs(t) * 100;
    return Math.round(100 * o) / 100;
}, t.prototype.AM = function(t, r, o, e, n) {
    var a, u, i, p = r / 12 / 100;
    return e ? 1 === e ? (a = h(o), u = Math.pow(1 + p, o) - 1) : console.log("not defined") : (a = h(12 * o), 
    u = Math.pow(1 + p, 12 * o) - 1), i = t * (a / u), Math.round(100 * i) / 100;
    function h(t) {
        return n && (t -= 1), p * Math.pow(1 + p, t);
    }
}, t.prototype.PI = function(t, r) {
    for (var o, e = 0, n = 2; n < arguments.length; n++) {
        var a;
        a = 1 / Math.pow(1 + t / 100, n - 1), e += arguments[n] * a;
    }
    return o = e / Math.abs(arguments[1]), Math.round(100 * o) / 100;
}, t.prototype.DF = function(t, r) {
    for (var o, e, n = [], a = 0; a < r; a++) o = 1 / Math.pow(1 + t / 100, a), e = Math.ceil(1e3 * o) / 1e3, 
    n.push(e);
    return n;
}, t.prototype.CI = function(t, r, o, e) {
    var n = o * Math.pow(1 + t / 100 / r, r * e);
    return Math.round(100 * n) / 100;
}, t.prototype.CAGR = function(t, r, o) {
    var e = Math.pow(r / t, 1 / o) - 1;
    return Math.round(1e4 * e) / 100;
}, t.prototype.LR = function(t, r, o) {
    return (t + r) / o * 100;
}, t.prototype.R72 = function(t) {
    return 72 / t;
}, t.prototype.WACC = function(t, r, o, e, n) {
    var a = t + r, u = t / a * o / 100 + r / a * e / 100 * (1 - n / 100);
    return Math.round(1e3 * u) / 10;
}, t.prototype.PMT = function(t, r, o) {
    return (-o * (t /= 100) / (1 - Math.pow(1 + t, -r))).toFixed(2);
}, t.prototype.IAR = function(t, r) {
    return (100 * ((1 + t / 100) / (1 + r / 100) - 1)).toFixed(2);
}, t.prototype.XIRR = function(t, r, e) {
    if (t.length != r.length) throw new Error("Number of cash flows and dates should match");
    var n, a;
    if (Array.prototype.slice.call(t).forEach(function(t) {
        t > 0 && (n = !0), t < 0 && (a = !0);
    }), !n || !a) throw new Error("XIRR requires at least one positive value and one negative value");
    e = e || 0;
    var u, i, p, h = 100, f = [];
    f.push(0);
    for (var v = 1; v < r.length; v++) f.push((i = r[0], p = r[v], Math.abs(p.getTime() - i.getTime()) / 31536e6));
    do {
        e = (u = e) - o(t, f, u), h--;
    } while (u.toFixed(5) != e.toFixed(5) && h > 0);
    var c = u.toFixed(5) != e.toFixed(5) ? null : 100 * e;
    return Math.round(100 * c) / 100;
}, t.prototype.RATE = function(t, r, o, e, n, a) {
    t = +t, r = -r, o = +o, e = +(e = void 0 === e ? 0 : e), n = +(n = void 0 === n ? 0 : n);
    for (var u = 0, i = !1, p = a = +(a = void 0 === a ? .01 : a); u < 100 && !i; ) {
        var h = Math.pow(p + 1, t), f = Math.pow(p + 1, t - 1), v = p - (e + h * o + r * (h - 1) * (p * n + 1) / p) / (t * f * o - r * (h - 1) * (p * n + 1) / Math.pow(p, 2) + (t * r * f * (p * n + 1) / p + r * (h - 1) * n / p));
        Math.abs(v - p) < 1e-6 && (i = !0), u++, p = v;
    }
    return i ? (100 * p).toFixed(2) : Number.NaN + p;
};

var e = t;

exports.FinanceClass = e;